// Inside bot attachment
// Senses data and sends it to remote host for processing

string sensorURL = "http://bot.betatechnologies.info/inworld/updateSensor.php";
key sensorRequest;

default
{
    state_entry()
    {
        llSay(0, "Attempting to sensorize...");
        llSensorRepeat("", NULL_KEY, AGENT|OS_NPC|ACTIVE|PASSIVE|SCRIPTED, 10.0, PI/2, 5.0);
    }
    
    attach(key where)
    {
        if (where != NULL_KEY)
        {
            llResetScript();
        }
    }
    
    sensor(integer numDetected)
    {
        integer i;
        
        for (i = 0; i < numDetected; i++)
        {
            
            /*llOwnerSay("Detected " +
                llDetectedName(i) + " at " +
                (string)llDetectedPos(i) + " type: " +
                (string)llDetectedType(i));*/
            
             // get a few more details
                
            list objectDetailsList = llGetObjectDetails(llDetectedKey(i), [OBJECT_PHANTOM, OBJECT_PRIM_EQUIVALENCE]);
            // now get the bounding box too
            list boundingBox = llGetBoundingBox(llDetectedKey(i));
            
            // Sending remotely
            sensorRequest = llHTTPRequest(sensorURL +
                "?key=" + llDetectedKey(i) +
                "&name=" + llEscapeURL(llDetectedName(i)) +
                "&pos=" + (string)llDetectedPos(i) +
                "&rot=" + (string)llDetectedRot(i) +
                "&vel=" + (string)llDetectedVel(i) +
                "&phantom=" + llList2String(objectDetailsList, 0) +
                "&prims=" + llList2String(objectDetailsList, 1) +
                "&bblo=" + llList2String(boundingBox, 0) +
                "&bbhi=" + llList2String(boundingBox, 1) +
                "&origin=sensor" +
                "&type=" + llDetectedType(i) +
                "&timestamp=" + llGetTimestamp(),
                [HTTP_METHOD, "GET"], "");
        }
    }
    
     http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == sensorRequest)
        {
            if (status == 200)
            {           
                // llOwnerSay(body);
            }
            else
            {
                llOwnerSay("HTTP Error " + (string)status + ": " + body);
            }
        }
    }
}